help = require 'hellp'

run = ->
	play(interactiveStrategy, makeRollUntilStrategy 20)

runTest = ->
	takeTurnTest()

takeTurnTest = ->
	console.log 'Take turn TEST'
	plan = makeRollUntilPlan 10
	takeTurn plan, makeTestDie SIDES

makeRollUntilPlan = (turnGoal = 20)->
	plan = (turn)->
		if turn >= turnGoal
			hold
		else
			roll

hold = (turnTotal, outcome)->
	[turnTotal, 0, true] # [scoreifOver, scoreIfNotOver, ifOver]
roll = (turnTotal, outcome)->
	if outcome is 1
		[1, 0, true]
	else
		[0, turnTotal+outcome, false]

takeTurn = (plan, dice = makeFairDie(), who='')->
	scoreForTurn = 0
	over = false
	while not over
		action = plan scoreForTurn
		outcome = dice()
		resAct = action scoreForTurn, outcome
		over = resAct[2]
		if not over
			scoreForTurn = resAct[1]
		else
			scoreForTurn = resAct[0]
		#console.log 
	return scoreForTurn

